<template>
  <div class="page-content padding-top">
    <list class="von-checkbox"  v-for="carConf in carConfig" style="margin-bottom:0px">
      <item thin style="background-color:#f5f5f5;font-weight:500">{{carConf.confName}}</item>
      <item v-for="(childCarConfItem,index) in carConf.childCarConf" class="item-icon-right"  @click.native="selectItem(childCarConfItem.confId,childCarConfItem.confName)" >
        {{childCarConfItem.confName}}
        <i class="icon ion-ios-checkmark-empty assertive" v-if="selectList.indexOf(childCarConfItem.confId) >= 0"></i>
        <input type="checkbox" name="" :value="childCarConfItem.confId" v-model="selectList">
      </item>
    </list>
  </div>
</template>
<script>
  import { bus } from 'bus.js'
  export default {
    data() {
      return {
        // name:['黑色','白色','米色','银色','灰色','棕色','香槟色','红色','蓝色','绿色','紫色','黄色','橙色','金色','其他'],
        ind:0,
        carConfig:[],
        selectList:[],
        selectNameList:[],
        defaultList:[],

      }
    },
    created(){
      var _this = this;
      

      axios.get(baseUrl+'/controller/getModelConfById',{params:{modelId:sess.get('modelId')}})
      .then(function(res){
      	console.log(res)
        var resJson = res.data.result
        for(var key in resJson){
          if (resJson[key] == 1) {
            _this.defaultList.push(key)
          }
        }

        axios.get(baseUrl+'/controller/getCarConfById',{params:{carId:sess.get('carId')}})
        .then(function(res){
        	console.log(res)
          _this.carConfig = res.data.result;
          for (var i = 0; i < res.data.result.length; i++) {
            for (var j = 0; j < res.data.result[i].childCarConf.length; j++) {
              if(res.data.result[i].childCarConf[j].selectedState){
                _this.selectList.push(res.data.result[i].childCarConf[j].confId);
                _this.selectNameList.push(res.data.result[i].childCarConf[j].confName)
              }
            }
          }
        });
        
      });

      
    },
    methods: {
      selectItem(a,b){
        if (this.selectList.indexOf(a) >=0 ) {//已有数据
          this.selectList.splice(this.selectList.indexOf(a), 1);
          this.selectNameList.splice(this.selectNameList.indexOf(b), 1);
        }else{
          this.selectList.push(a);
          this.selectNameList.push(b);
        }
        bus.$emit('configList', this.selectList);
        bus.$emit('configNameList', this.selectNameList);
      }
    }
  }
</script>
<style type="text/css">

  .icon.show{
    display: block;
  }
</style>
